package so.ifl.view.servlet;

import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import so.ifl.commons.tools.StringHelper;
import so.ifl.commons.tools.pinter.Iprinter;
import so.ifl.commons.tools.pinter.PrinterFactory;

/**
 *create by aaron.lu
 *create at 2012-2-20 下午11:56:26
 *<mailto: atyuan.lu@gmail.com>
 **/
public class DoPrint extends HttpServlet {
	Logger logger_ = LoggerFactory.getLogger(this.getClass());
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException{
		
		String which = request.getParameter("which");
		
		if (StringHelper.isNotEmpty(which)) {
			
			Iprinter printer = PrinterFactory.getPrinter(which);//获取printer实例
			
			Map<String, Object> data;
			try {
				data = printer.getData(request);//获取需要写的数据
				
				printer.print(data, response, request);//将pdf写道
			} catch (Exception e) {
				e.printStackTrace();
				logger_.error(e.getMessage());
				
				//TODO 跳转错误页面
			}
			
			
		}
		
	}

}
